home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / COMM / MSKRMSRC.ARJ / MSNTNI.ASM < prev    next >
Assembly Source File  |  1991-10-24  |  18KB  |  707 lines

  1.     NAME    MSNTNI
  2. ; File MSNTNI.ASM
  3. ; Telnet interface to MS-DOS Kermit
  4. ;
  5. ; Copyright (C) 1991, Trustees of Columbia University in the
  6. ;  City of New York.  Permission is granted to any individual or
  7. ;  institution to use, copy, or redistribute this software as long as
  8. ;  it is not sold for profit and this copyright notice is retained.
  9. ; Written by Joe R. Doupnik, Utah State University, 
  10. ;  jrd@cc.usu.edu, jrd@usu.Bitnet.
  11. ;
  12. ; Edit history
  13. ; 6 Sept 1991 version 3.11
  14. ; Last edit 16 Sept 1991
  15.     include    mssdef.h
  16.  
  17. getintv    equ    35h        ; DOS get interrupt vector to es:bx
  18. bapicon    equ    0a0h        ; 3Com BAPI, connect to port
  19. bapidisc equ    0a1h        ; 3Com BAPI, disconnect
  20. bapiwrit equ    0a4h        ; 3Com BAPI, write block
  21. bapiread equ    0a5h        ; 3Com BAPI, read block
  22. bapibrk    equ    0a6h        ; 3Com BAPI, send short break
  23. bapistat equ    0a7h        ; 3Com BAPI, read status (# chars to be read)
  24. bapihere equ    0afh        ; 3Com BAPI, presence check
  25. bapieecm equ    0b0h        ; 3Com BAPI, enable/disable ECM char
  26. bapiecm    equ    0b1h        ; 3Com BAPI, trap Enter Command Mode char
  27.  
  28. data    segment public 'kdata'
  29.     extrn    tcptos:word    ; top of stack for TCP code
  30.     extrn    flags:byte, yflags:byte, portval:word
  31. data    ends
  32.  
  33. _TEXT    SEGMENT  WORD PUBLIC 'CODE'
  34. _TEXT    ENDS
  35. _DATA    SEGMENT  WORD PUBLIC 'DATA'
  36. _DATA    ENDS
  37. CONST    SEGMENT  WORD PUBLIC 'CONST'
  38. CONST    ENDS
  39. _BSS    SEGMENT  WORD PUBLIC 'BSS'
  40. _BSS    ENDS
  41. DGROUP    GROUP    CONST, _BSS, _DATA
  42.     ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP
  43.  
  44. _DATA      SEGMENT
  45.     public _kmyip, _knetmask, _kdomain, _kgateway, _kns1, _kns2, _khost
  46.     public _kbcast, _bapibuf, _bapireq, _bapiret, _msgcnt, _msgbuf
  47.     public    _display_mode
  48.  
  49.     extrn    _my_ip_addr:dword, _sin_mask:dword
  50.  
  51.         db 'DUMMY'           ; null pointer guard
  52. _kmyip        db 33 dup (0)        ; our IP number
  53. _knetmask    db 33 dup (0)        ; our netmask
  54. _kdomain    db 33 dup (0)        ; our domain
  55. _kgateway     db 33 dup (0)        ; our gateway
  56. _kns1        db 33 dup (0)        ; our nameserver #1
  57. _kns2        db 33 dup (0)        ; our nameserver #2
  58. _khost        db 33 dup (0)        ; remote host name/IP #
  59. _kbcast        db 33 dup (0)        ; broadcast IP
  60. _kserver    dw    0        ; non-zero for Kermit server
  61. bpprefix db    'Bootp ',0        ; prefix for Bootp provided IP addr
  62. oldint14 dd    0            ; original Int 14h owner
  63. oldint8    dd    0            ; original Int 8 owner
  64. tcpstack dd    0            ; TCP code stack
  65. stack8    dd    0            ; stack at Int 8 invokation
  66. kstack    dw    0            ; Kermit mainline stack pointer
  67. tempax    dw    0            ; a temp
  68. tcpflag    db    0        ; who is running TCP code: 1=Kermit, 2=Int 8
  69. tcpdata    dw    0            ; Kermit offset of "tcpdata" block
  70. int8cnt    db    0            ; Int 8 times called counter
  71. _display_mode db 0            ; msg, none if == 0
  72. opcode    db    0            ; BAPI op code
  73. userbuf    dd    0            ; BAPI user's comms buffer address
  74. _bapireq dw    0            ; BAPI count of chars requested
  75. _bapiret dw    0            ; BAPI count of chars processed
  76. buflen    equ    512
  77. _bapibuf db    buflen dup (0)        ; BAPI buffer in TCP address space
  78. _msgcnt    dw    0            ; count of bytes in msg buffer
  79. _msgbuf    db    256 dup (0)        ; interrupt level msg buffer
  80. _DATA      ENDS
  81.  
  82.  
  83. _TEXT    segment
  84.     ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP
  85.     extrn    _int14handler:near, _main:near, _exit:near, _pkt_release:near
  86.     extrn    _int8tick:near, _bcopy:near, _itoa:near, _strlen:near
  87.     extrn    _strcpy:near
  88.  
  89. public    _enable
  90. enable    proc    near
  91. _enable    equ    this byte
  92.     sti
  93.     ret
  94. enable    endp
  95.  
  96. public    _disable
  97. disable    proc    near
  98. _disable equ    this byte
  99.     cli
  100.     ret
  101. disable    endp
  102.  
  103. ; Hook Interrupts 8h and 14h. Return AX = 1 if successful else 0.
  104.     public    _hookvect
  105. hookvect proc    near
  106. _hookvect equ    this byte
  107.     push    bp
  108.     mov    bp,sp
  109.     mov    ax,bp
  110.     add    ax,2+2            ; C sp just before this call
  111.     mov    word ptr tcpstack,ax    ; save as main prog stack level
  112.     push    es
  113.     mov    ah,getintv        ; get interrupt vector
  114.     mov    al,14h            ; vector number
  115.     int    dos
  116.     mov    ax,es
  117.     mov    cx,cs
  118.     cmp    ax,cx            ; points to us now?
  119.     je    hook1            ; yes, don't touch again
  120.     mov    word ptr DGROUP:oldint14+2,ax    ; save segment
  121.     mov    word ptr DGROUP:oldint14,bx    ; save offset
  122.     mov    dx,offset ourserial     ; new handler
  123.     push    ds
  124.     mov    ax,cs            ; segment
  125.     mov    ds,ax
  126.     mov    al,14h            ; for Int 14h
  127.     mov    ah,25H            ; set interrupt address from ds:dx
  128.     int    dos
  129.     pop    ds
  130.  
  131. hook1:    mov    ah,getintv        ; get interrupt vector
  132.     mov    al,8            ; vector number
  133.     int    dos
  134.     mov    ax,es
  135.     mov    cx,cs
  136.     cmp    ax,cx            ; points to us now?
  137.     je    hook2            ; e = yes, do not touch
  138.     mov    word ptr DGROUP:oldint8+2,ax    ; save segment
  139.     mov    word ptr DGROUP:oldint8,bx    ; save offset
  140.     mov    dx,offset ourtimer     ; new handler
  141.     push    ds
  142.     mov    ax,cs            ; segment
  143.     mov    ds,ax
  144.     mov    al,8            ; for Int 8
  145.     mov    ah,25H            ; set interrupt address from ds:dx
  146.     int    dos
  147.     pop    ds
  148. hook2:    mov    tcpflag,1     ; say Kermit but not Int 8 is running TCP
  149.     mov    ax,1            ; return 1 for success
  150.     pop    es
  151.     pop    bp
  152.     ret
  153. hook3:    call    unhookvect        ; put any back
  154.     xor    ax,ax            ; return 0 for failure
  155.     pop    es
  156.     pop    bp
  157.     ret
  158. hookvect endp
  159.  
  160.     public    _unhookvect
  161. unhookvect proc    near
  162. _unhookvect equ    this byte
  163.     push    bp
  164.     mov    bp,sp
  165.     push    es
  166.     push    bx
  167.     push    cx
  168.     clc
  169.     mov    tempax,0        ; assume failure status
  170.     mov    ah,getintv        ; get interrupt vector
  171.     mov    al,14h            ; vector number
  172.     int    dos
  173.     jc    unhook1            ; c = failed
  174.     mov    ax,es            ; es:bx is current owner, us?
  175.     mov    cx,cs
  176.     cmp    ax,cx            ; seg should be right here
  177.     jne    unhook1            ; ne = is not
  178.     cmp    bx,offset ourserial    ; should be the same too
  179.     jne    unhook1            ; ne = is not, let them have the int
  180.     mov    ax,word ptr DGROUP:oldint14+2    ; segment
  181.     mov    dx,word ptr DGROUP:oldint14    ; offset
  182.     mov    cx,dx
  183.     or    cx,ax            ; was it used by us?
  184.     jz    unhook1            ; z = no, leave alone
  185.     push    ds
  186.     mov    ds,ax
  187.     mov    al,14h            ; for Int 14h
  188.     mov    ah,25H            ; set interrupt address from ds:dx
  189.     int    dos
  190.     pop    ds
  191.     mov    word ptr DGROUP:oldint14,0
  192.     mov    word ptr DGROUP:oldint14+2,0
  193.     mov    tempax,1        ; success so far
  194.  
  195. unhook1:mov    ah,getintv        ; get interrupt vector
  196.     clc
  197.     mov    al,8            ; vector number
  198.     int    dos
  199.     jc    unhook2            ; c = failed
  200.     mov    ax,es            ; es:bx is current owner, us?
  201.     mov    cx,cs
  202.     cmp    ax,cx            ; seg should be right here
  203.     jne    unhook2            ; ne = is not
  204.     cmp    bx,offset ourtimer    ; should be the same too
  205.     jne    unhook2            ; ne = is not, let them have the int
  206.     mov    ax,word ptr DGROUP:oldint8+2    ; segment
  207.     mov    dx,word ptr DGROUP:oldint8    ; offset
  208.     mov    cx,dx
  209.     or    cx,ax            ; was it used by us?
  210.     jz    unhook2            ; z = no, leave alone
  211.     push    ds
  212.     mov    ds,ax
  213.     mov    al,8            ; for Int 8
  214.     mov    ah,25H            ; set interrupt address from ds:dx
  215.     int    dos
  216.     pop    ds
  217.     and    tcpflag,not 2        ; Int 8 no longer touches TCP
  218.     mov    word ptr DGROUP:oldint8,0
  219.     mov    word ptr DGROUP:oldint8+2,0
  220.     mov    tempax,1        ; success status
  221.     jmp    short unhook3
  222. unhook2:mov    tempax,0        ; failure
  223. unhook3:mov    ax,tempax        ; return status (1=success, 0=fail)
  224.     pop    cx
  225.     pop    bx
  226.     pop    es
  227.     pop    bp
  228.     ret
  229. unhookvect endp
  230.  
  231. ; Int 8 routine to call the TCP code if Kermit does not.
  232. ourtimer proc near
  233.     push    ds
  234.     push    ax
  235.     mov    ax,dgroup        ; set addressibility to our dgroup
  236.     mov    ds,ax
  237.     pushf                ; simulate interrupt invokation
  238.     call    dword ptr DGROUP:oldint8 ; call previous owner of Int 8
  239.  
  240.     mov    ax,dgroup
  241.     mov    ds,ax
  242.     test    tcpflag,1+2        ; is TCP code running now?
  243.     jnz    ourtim2            ; nz = yes, so we don't run now
  244.     mov    al,int8cnt        ; get our times called counter
  245.     inc    al            ; up once again
  246.     and    al,7            ; keep 3 bits, about .5 sec @18.2tic/s
  247.     mov    int8cnt,al        ; store
  248.     or    al,al            ; is it zero?
  249.     jnz    ourtim2            ; nz = no, go away for awhile
  250.     or    tcpflag,2        ; say we are running the TCP code
  251.     push    bp
  252.     push    bx
  253.     push    cx
  254.     push    dx
  255.     push    si
  256.     push    di
  257.     push    es
  258.     mov    ax,dgroup        ; set addressibility to our dgroup
  259.     mov    ds,ax
  260.     cli
  261.     mov    ax,ss
  262.     mov    word ptr stack8+2,ax    ; save current stack
  263.     mov    word ptr stack8,sp
  264.     mov    ax,word ptr tcpstack+2    ; get TCP stack seg
  265.     mov    ss,ax            ; set to TCP stack
  266.     mov    sp,word ptr tcpstack
  267.     sti                ; restart interrupts
  268.     call    _int8tick        ; read some packets
  269.     mov    ax,word ptr stack8+2    ; get original stack seg
  270.     cli
  271.     mov    ss,ax
  272.     mov    sp,word ptr stack8
  273.     sti
  274.     pop    es
  275.     pop    di
  276.     pop    si
  277.     pop    dx
  278.     pop    cx
  279.     pop    bx
  280.     pop    bp
  281.     and    tcpflag,not 2        ; finished our running of TCP code
  282. ourtim2:pop    ax
  283.     pop    ds
  284.     iret
  285. ourtimer endp
  286.  
  287. ; This routine is invoked from outside by Int 14h. Enter with the caller's
  288. ; registers but our CS. Switch stacks and data segments.
  289. ; This version supports 3Com BAPI calls and does the near/far stuff via
  290. ; a local buffer.
  291. ourserial proc    near            ; Interrupt 14h service routine
  292.     assume    ds:DGROUP
  293.     push    ds
  294.     push    ax
  295.     mov    ax,dgroup        ; set addressibility to our dgroup
  296.     mov    ds,ax
  297.     pop    ax
  298.     test    tcpflag,2        ; is Int 8 running TCP?
  299.     jz    ourser8            ; z = no
  300.     mov    ah,1            ; say no char written
  301.     xor    cx,cx            ; chars written
  302.     pop    ds
  303.     iret
  304.  
  305. ourser8:or    tcpflag,1        ; say we are running TCP
  306.     push    es            ; save regs on the user's stack
  307.     push    di
  308.     push    si
  309.     push    dx
  310.     push    bx
  311.     push    bp
  312.     push    ax
  313.     mov    ax,dgroup        ; set addressibility to our dgroup
  314.     mov    ds,ax
  315.     pop    ax
  316.     mov    kstack,sp        ; remember caller's stack now
  317.     mov    sp,word ptr tcpstack    ; move to our TCP stack
  318.     mov    word ptr userbuf,bx    ; remember caller's es:bx
  319.     mov    word ptr userbuf+2,es
  320.     mov    _bapireq,cx        ; requested char count to TCP code
  321.     mov    _bapiret,0        ; init returned CX char count
  322.     mov    opcode,ah        ; remember operation for return proc
  323.     cmp    ah,bapihere        ; presence check?
  324.     jne    ourser6            ; ne = no
  325.     mov    ax,0af01h        ; return this value
  326.     jmp    ourser4            ; done
  327.  
  328. ourser6:
  329.     cmp    ah,bapiwrit        ; BAPI write?
  330.     jne    ourser2            ; ne = no
  331.     push    ax
  332.     push    cx
  333.     push    es
  334.     push    ds
  335.     mov    di,offset DGROUP:_bapibuf ; where it goes
  336.     mov    si,bx            ; es:bx, whence it comes
  337.     mov    bx,es
  338.     mov    ax,ds
  339.     mov    es,ax
  340.     mov    ds,bx
  341.     cld
  342.     cmp    cx,buflen        ; largest block i/o we allow here
  343.     jbe    ourser1            ; be = ok
  344.     mov    cx,buflen        ; truncate the request
  345. ourser1:shr    cx,1
  346.     jnc    ourser1a
  347.     movsb
  348. ourser1a:rep    movsw            ; copy their buffer to ours
  349.     pop    ds
  350.     pop    es
  351.     pop    cx
  352.     pop    ax
  353. ourser2:cmp    ah,bapiread        ; read?
  354.     jne    ourser3            ; ne = no
  355.     cmp    _msgcnt,0        ; any outstanding msgs from TCP?
  356.     je    ourser3            ; e = no msgs
  357.     call    oursmsg            ; send back the msgs instead
  358.     jmp    short ourser4        ; ax has status of ok
  359. ourser3:sti                ; let other ints happen
  360.     mov    bx,dgroup        ; set up es to dgroup too
  361.     mov    es,bx            ; bx is not needed at this time
  362.     xchg    ah,al            ; put function code in al
  363.     xor    ah,ah
  364.     push    ax            ; setup call frame
  365.  
  366.     call    _int14handler        ; a near call, _int14handler(ax)
  367.  
  368.     cli                ; reg ax has return status
  369.     add    sp,2            ; clean stack
  370.     mov    cx,dgroup        ; safety check, not really needed
  371.     mov    ds,cx
  372.     mov    cx,_bapiret        ; count of chars returned
  373.     cmp    opcode,bapiread        ; BAPI read?
  374.     jne    ourser4            ; ne = no
  375.     jcxz    ourser4            ; z = nothing to copy
  376.     push    ax
  377.     push    cx
  378.     mov    si,offset DGROUP:_bapibuf ; whence it comes
  379.     mov    di,word ptr userbuf    ; where it goes
  380.     mov    ax,word ptr userbuf+2    ; segment
  381.     mov    es,ax
  382.     cld
  383.     shr    cx,1
  384.     jnc    ourser3a
  385.     movsb
  386. ourser3a:rep    movsw            ; copy our buffer to theirs
  387.     pop    cx            ; return count in cx
  388.     pop    ax            ; return result code in ah, cnt in cx
  389. ourser4:clc                ; assume success
  390.     xchg    ah,al            ; put return status in ah
  391.     xor    al,al
  392.     cmp    ah,3            ; serious error status?
  393.     jb    ourserx            ; b = no, zero is success
  394.     stc                ; set carry too
  395. ourserx:mov    sp,kstack         ; move to caller's stack
  396.     and    tcpflag,not 1        ; say we are not running TCP
  397.     pop    bp
  398.     pop    bx
  399.     pop    dx
  400.     pop    si
  401.     pop    di
  402.     pop    es
  403.     pop    ds
  404.     iret                ; AX and CX are changed as returns
  405. ourserial endp
  406.  
  407. oursmsg    proc    near
  408.     mov    cx,_msgcnt
  409.     jcxz    ourser3            ; z = no msgs
  410.     cmp    cx,_bapireq        ; longer than request?
  411.     jbe    oursmsg1        ; be = no
  412.     mov    cx,_bapireq        ; do this much now
  413. oursmsg1:push    cx
  414.     mov    si,offset DGROUP:_msgbuf ; whence it comes
  415.     mov    di,word ptr userbuf    ; where it goes
  416.     mov    ax,word ptr userbuf+2    ; segment
  417.     mov    es,ax
  418.     cld
  419.     rep    movsb            ; copy our buffer to theirs
  420.     pop    cx            ; return count in cx
  421.     mov    _bapiret,cx        ; return count to user
  422.     sub    _msgcnt,cx        ; deduct chars relayed
  423.     cmp    _msgcnt,0        ; examine remainder
  424.     je    oursmsg3        ; e = none
  425.     mov    ax,_msgcnt        ; count
  426.     push    ax
  427.     mov    ax,offset DGROUP:_msgbuf
  428.     push    ax            ; destination
  429.     add    ax,_msgcnt        ; source
  430.     push    ax
  431.     call    _bcopy            ; copy to beginning of buffer
  432.     add    sp,6            ; clean stack
  433. oursmsg3:mov    ax,0            ; return status of success
  434.     ret
  435. oursmsg    endp
  436.  
  437.  
  438. ; tcpaddress db    '127.0.0.1',(32-($-tcpaddress)) dup (0),0
  439. ; tcpsubnet  db    '255.255.255.0',(32-($-tcpsubnet)) dup (0),0
  440. ; tcpdomain  db    'loopback',(32-($-tcpdomain)) dup (0),0
  441. ; tcpgateway db    '127.0.0.1',(32-($-tcpgateway)) dup (0),0
  442. ; tcpprimens db    '127.0.0.1',(32-($-tcpprimens)) dup (0),0
  443. ; tcpsecondns db '127.0.0.1',(32-($-tcpsecondns)) dup (0),0
  444. ; tcphost db    (32-($-tcphost)) dup (0),0
  445. ; tcpbcast db    0ffh
  446. ; tcpdata dw    offset tcpaddress ; externally visible far pointers
  447. ;     dw    offset tcpsubnet
  448. ;     dw    offset tcpdomain
  449. ;     dw    offset tcpgateway
  450. ;     dw    offset tcpprimens
  451. ;     dw    offset tcpsecondns
  452. ;    dw    offset tcphost
  453. ;    dw    offset tcpbcast
  454.  
  455.     public    ktcpstart
  456. ktcpstart proc    far
  457.     ASSUME    DS:DATA, ES:DGROUP
  458.     push    es            ; save regs on main Kermit stack
  459.     push    ds
  460.     push    di
  461.     push    si
  462.     push    dx
  463.     push    cx
  464.     push    bx
  465.     push    bp
  466.     mov    ax,DGROUP
  467.     mov    es,ax            ; destination is the TCP module
  468.     cld
  469.     mov    tcpdata,bx        ; store offset of Kermit data block
  470.     mov    si,[bx]            ; get offset of our IP address
  471.     mov    di,offset DGROUP:_kmyip    ; our storage slot
  472.     mov    cx,16            ; max bytes
  473. start5:    lodsb
  474.     stosb
  475.     or    al,al
  476.     loopne    start5            ; copy IP address string, asciiz
  477.     xor    al,al            ; extra terminator
  478.     stosb
  479.     mov    si,[bx+2]        ; get offset in Kermit
  480.     mov    di,offset DGROUP:_knetmask
  481.     mov    cx,16
  482. start6:    lodsb
  483.     stosb
  484.     or    al,al
  485.     loopne    start6
  486.     xor    al,al
  487.     stosb
  488.     mov    si,[bx+4]            ; get offset in Kermit
  489.     mov    di,offset DGROUP:_kdomain
  490.     mov    cx,32
  491. start7:    lodsb
  492.     stosb
  493.     or    al,al
  494.     loopne    start7
  495.     xor    al,al
  496.     stosb
  497.     mov    si,[bx+6]            ; get offset in Kermit
  498.     mov    di,offset DGROUP:_kgateway
  499.     mov    cx,32
  500. start8:    lodsb
  501.     stosb
  502.     or    al,al
  503.     loopne    start8
  504.     xor    al,al
  505.     stosb
  506.     mov    si,[bx+8]            ; get offset in Kermit
  507.     mov    di,offset DGROUP:_kns1
  508.     mov    cx,32
  509. start9:    lodsb
  510.     stosb
  511.     or    al,al
  512.     loopne    start9
  513.     xor    al,al
  514.     stosb
  515.     mov    si,[bx+10]            ; get offset in Kermit
  516.     mov    di,offset DGROUP:_kns2
  517.     mov    cx,32
  518. start10:lodsb
  519.     stosb
  520.     or    al,al
  521.     loopne    start10
  522.     xor    al,al
  523.     stosb
  524.     mov    si,[bx+12]            ; get offset in Kermit
  525.     mov    di,offset DGROUP:_khost
  526.     mov    cx,32
  527. start11:lodsb
  528.     stosb
  529.     or    al,al
  530.     loopne    start11
  531.     xor    al,al
  532.     stosb
  533.     mov    si,[bx+14]            ; broadcast byte address
  534.     mov    di,offset DGROUP:_kbcast
  535.     mov    cx,32
  536. start12:lodsb
  537.     stosb
  538.     or    al,al
  539.     loopne    start12
  540.     xor    al,al
  541.     stosb
  542.     mov    es:_display_mode,0    ; presume quiet screen
  543.     test    flags.remflg,dquiet    ; quiet display mode?
  544.     jnz    start13            ; nz = yes. Don't write to screen
  545.     inc    es:_display_mode    ; say can write to screen
  546. start13:mov    bx,tcptos        ; top of stack for tcp code
  547.  
  548.     assume    ds:DGROUP, ES:NOTHING
  549.     
  550.     mov    ax,dgroup        ; set addressibility to our dgroup
  551.     mov    ds,ax
  552.     mov    es,ax
  553.     mov    word ptr tcpstack+2,ax    ; set TCP stack seg
  554.     mov    word ptr kstack,sp    ; store Kermit's stack ptr
  555.     mov    sp,bx            ; new TCP stack pointer, DGROUP based
  556.     mov    bp,sp            ; preset this as insurance
  557.     or    tcpflag,1        ; say this is running TCP code
  558.     call    _main            ; call the C code
  559.     and    tcpflag,not 1        ; finished running tcp code
  560.     mov    sp,word ptr kstack    ; restore for Kermit's main stack
  561.     pop    bp            ; restore regs, Kermit's main stack
  562.     pop    bx
  563.     pop    cx
  564.     pop    dx
  565.     pop    si
  566.     pop    di
  567.     pop    ds
  568.     pop    es
  569.     ret                ; return to caller
  570. ktcpstart endp
  571.  
  572.     public    ktcpstop
  573. ktcpstop proc    far
  574.     assume    ds:dgroup, es:nothing
  575.     push    es            ; save regs on the user's stack
  576.     push    ds
  577.     push    di
  578.     push    si
  579.     push    dx
  580.     push    cx
  581.     push    bx
  582.     push    bp
  583.     mov    ax,dgroup        ; set addressibility to our dgroup
  584.     mov    ds,ax
  585.     mov    kstack,sp        ; remember Kermit's main sp
  586.     or    tcpflag,1        ; say we are running TCP code
  587.     mov    ax,word ptr tcpstack    ; set sp to TCP sp
  588.     mov    sp,ax
  589.     mov    bp,sp            ; preset this as insurance
  590.     push    ds
  591.     pop    es
  592.     xor    ax,ax
  593.     push    ax            ; exit(0) setup
  594.     call    _exit
  595.     add    sp,2            ; returns status in AX
  596.     mov    tempax,ax
  597.     mov    ax,word ptr tcpstack    ; set sp to TCP sp again
  598.     mov    sp,ax
  599.     mov    bp,sp            ; preset this as insurance
  600.     call    _pkt_release        ; do this as insurance
  601.     mov    ax,tempax        ; regain status
  602.     push    ax
  603.     call    unhookvect        ; ditto
  604.     pop    ax
  605.     mov    tcpflag,0        ; no one is running the TCP code
  606.     mov    sp,kstack
  607.     pop    bp            ; restore regs, Kermit's main stack
  608.     pop    bx
  609.     pop    cx
  610.     pop    dx
  611.     pop    si
  612.     pop    di
  613.     pop    ds
  614.     pop    es
  615.     ret                ; return to caller
  616. ktcpstop endp
  617.  
  618.     public    _readback
  619. _readback proc    near
  620.     assume    ds:dgroup, es:dgroup
  621.     push    bp
  622.     mov    bp,sp
  623.     push    si
  624.     push    di
  625.     push    es
  626.     mov    ax,data
  627.     mov    es,ax
  628.     mov    si,offset dgroup:_kmyip
  629.     push    si
  630.     push    si
  631.     call    _strlen                ; get length of string
  632.     add    sp,2
  633.     pop    si
  634.     mov    di,tcpdata            ; copy to Kermit main body
  635.     mov    di,es:[di]            ; offset of the string
  636.     mov    cx,ax
  637.     cld
  638.     rep    movsb
  639.     xor    al,al
  640.     stosb                    ; terminator
  641.     mov    si,offset dgroup:_knetmask
  642.     mov    di,tcpdata
  643.     mov    di,es:[di+2]
  644.     mov    cx,17
  645.     rep    movsb
  646.     stosb                    ; terminator
  647.     mov    si,offset dgroup:_kgateway
  648.     mov    di,tcpdata
  649.     mov    di,es:[di+6]
  650.     mov    cx,17
  651.     rep    movsb
  652.     stosb                    ; terminator
  653.     mov    si,offset dgroup:_kns1
  654.     mov    di,tcpdata
  655.     mov    di,es:[di+8]
  656.     mov    cx,17
  657.     rep    movsb
  658.     stosb                    ; terminator
  659.     mov    si,offset dgroup:_kns2
  660.     mov    di,tcpdata
  661.     mov    di,es:[di+10]
  662.     mov    cx,17
  663.     rep    movsb
  664.     stosb                    ; terminator
  665.     pop    es
  666.     pop    si
  667.     pop    di
  668.     pop    bp
  669.     ret
  670. _readback endp
  671.  
  672. ; Track Telnet echo variable (0 do not do local echo) into terminal emulator
  673. ; and Kermit main body. Call this each time Telnet options change echo.
  674.     public    _kecho
  675. _kecho    proc    near
  676.     assume    ds:data, es:dgroup
  677.     push    bp
  678.     mov    bp,sp
  679.     push    ds
  680.     push    es
  681.     push    si
  682.     push    ax
  683.     mov    ax,data            ; Kermit main data segment
  684.     mov    ds,ax
  685.     mov    ax,dgroup
  686.     mov    es,ax
  687.     mov    ax,[bp+4+0]        ; get Telnet _echo variable
  688.     and    yflags,not lclecho    ; assume no local echo in emulator
  689.     or    al,al            ; Telnet local echo is off?
  690.     jz    kecho1            ; z = yes
  691.     mov    al,lclecho        ; lclecho flag for emulator
  692. kecho1:    or    yflags,al        ; set terminal emulator
  693.     mov    si,portval
  694.     mov    [si].ecoflg,al        ; set mainline SET echo flag
  695.     pop    ax
  696.     pop    si
  697.     pop    es
  698.     pop    ds
  699.     pop    bp
  700.     ret
  701. _kecho    endp
  702. _TEXT    ends
  703.         end
  704.  
  705.